package org.linlinjava.litemall.db.service;

import org.apache.commons.lang.StringUtils;
import org.linlinjava.litemall.db.dao.AgedmallHospitalSendMapper;
import org.linlinjava.litemall.db.dao.app.AppHospitalSendMapper;
import org.linlinjava.litemall.db.domain.AgedmallHospitalSend;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class AgedmallHospitalSendService {
    @Resource
    private AppHospitalSendMapper appHospitalSendMapper;
    @Resource
    private AgedmallHospitalSendMapper agedmallHospitalSendMapper;

    public List<AgedmallHospitalSend> getByStoreAndGoods(Integer storeId, Integer goodsId) {
        return appHospitalSendMapper.getByStoreAndGoods(storeId, goodsId);
    }

    public List<AgedmallHospitalSend> getByStoreAndGoodsByMap(Integer storeId, Integer goodsId, Map<Integer, List<AgedmallHospitalSend>> hospitalSendMap) {
        List<AgedmallHospitalSend> list = hospitalSendMap.get(storeId);
        if(list == null) {
            return new ArrayList<>();
        }
        List<AgedmallHospitalSend> resultList = list.parallelStream().filter(hs-> hs.getGoodsType() == 1 || hs.getGoodsIds().contains(goodsId.toString())).collect(Collectors.toList());
        return resultList;
    }

    public List<AgedmallHospitalSend> getListByStoreGoodsIds(List<Integer> storeGoodsIdList) {
        if(storeGoodsIdList == null || storeGoodsIdList.size() == 0) {
            return new ArrayList<>();
        }
        return appHospitalSendMapper.getListByStoreGoodsIds(storeGoodsIdList);
    }

    public List<AgedmallHospitalSend> getByCitys(List<String> citys) {
        return appHospitalSendMapper.getByCitys(citys);
    }

    public AgedmallHospitalSend getById(Integer hospId) {
        return agedmallHospitalSendMapper.selectByPrimaryKey(hospId);
    }
}
